package com.rzrk.centerlogserver.mq;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component
public class LogStoreManager {
	Logger log = LoggerFactory.getLogger(getClass());
	List<LogStoreStrategy> logStoreStrategyList = new ArrayList<LogStoreStrategy>();
	@Resource
	LogStoreStrategyNormal logStoreStrategyNormal;
	@Resource
	LogStoreStrategyOperate logStoreStrategyOperate;
	@Resource
	LogStoreStrategyException logStoreStrategyException;
	
	@PostConstruct
	public void init(){
		logStoreStrategyList.add(logStoreStrategyNormal);
		logStoreStrategyList.add(logStoreStrategyOperate);
		logStoreStrategyList.add(logStoreStrategyException);
		log.warn("logStoreStrategy [ok]");
	}
	
	public void save(String msg){
		try {
			for(LogStoreStrategy logStoreStrategy : logStoreStrategyList){
				if(logStoreStrategy.save(msg)){
					break;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error("保存异常",msg);
			log.error(ExceptionUtils.getStackTrace(e));
		}
	}
}
